
// 虚拟容器基类
function Virtual() {
}


Object.extend(function (base) {



    // 扩展属性集支持
    extendProperties(Virtual);



    // 标记为虚拟对象
    this.__virtual = true;


    // 容器类型
    this.__container = 3;



    // 向下查找规则
    this.__find = '__children';




    this.init = function () {

        this.parent = this.__template = null;

        this.__fields = $create(this.__defaults);
        this.__children = [];
    }



    this.__load = function (options) {

        if (options[1])
        {
            loadProperties(this, options[1]);
        }

        if (this.__template = options[2])
        {
            buildObjectChildren(this, options[2]);
        }
    }



    // 获取可视子项集合
    this.getVisualObjects = function (outputs, destroyObjectFn) {

        var children = this.__children;
        var index = 0;
        var item;

        while (item = children[index++])
        {
            if (item.__virtual)
            {
                item.getVisualObjects(outputs, destroyObjectFn);
            }
            else
            {
                outputs.push(item);
            }
        }
    }




    this.destroy = function () {

        var children;

        if (children = this.__children)
        {
            for (var i = children.length; i--;)
            {
                children[i].destroy();
            }
        }

        this.parent = this.__children = this.__template = null;
    }



}, Virtual);




function loadVirtuallDelay(options) {

    if (options[1])
    {
        loadProperties(this, options[1]);
    }

    this.__template = options[2];
}



// 标记虚拟对象无效
function invalidateVirtualObject() {

    var object = this;

    if (object.__template)
    {
        while (object = object.parent)
        {
            if (!object.__virtual)
            {
                if (!object.__changed)
                {
                    object.invalidate();
                }
                break;
            }
        }
    }
}


